# -*- coding: utf-8 -*-
# @Time     : 2021/5/17 16:25
# @Author   : pengrenjie
# @Email    : 941257162@.com
# @File     : 回合制对战游戏.py
import random
class Player:
    blood = 100
    lost_blood = [ 10, 5]
    def __init__(self,name,sex):
        self.name = name
        self.sex = sex

        # self.equip = null
    def PK(self,player):

        if self == player:
            print("无法攻击自己")
        else:
            # if hasattr(self,"equip"):
            if random.choice([0,1]) == 0:
                player.blood = player.blood - self.lost_blood[1]
                print(f"{player.name}装备了防弹衣,{self.name}对{player.name}造成了5点伤害,剩余血量:{player.blood}")
            else:
                player.blood = player.blood - self.lost_blood[0]
                print(f"{player.name}没有装备,{self.name}对{player.name}造成了10点伤害,剩余血量:{player.blood}")
            if player.blood <= 0:
                print(f"{player.name}血量为0,无法战斗")
                exit()




            #     self.blood = self.blood - player.lost_blood[1]
            #     player.blood = player.blood - self.lost_blood[1]
            #     print(f"{player.name}对{self.name}造成了5点伤害,剩余血量:{self.blood}")
            #     print(f"{self.name}对{player.name}造成了5点伤害,剩余血量:{player.blood}")
            # else:
            #     self.blood = self.blood - player.lost_blood[0]
            #     player.blood = player.blood - self.lost_blood[0]
            #     print(f"{player.name}对{self.name}造成了10点伤害,剩余血量:{self.blood}")
            #     print(f"{self.name}对{player.name}造成了10点伤害,剩余血量:{player.blood}")





class Room:
    def __init__(self,name):
        self.name = name
        self.nums = []
    def addplr(self,player):
        if len(self.nums) <= 2:
            self.nums.append(player)

            print(f"{player.name}加入了{self.name}房间")





#
# player1 = Palyer("prj",23)
#
# player2= Palyer("ppp",23)
# player1.PK(player2)
# player2.PK(player1)
# room1 = Room("sc")
# room1.addroom(player1)
# room1.addroom(player2)
print("回合制游戏".center(30,'='))
print("1.创建角色\n"
      "2.创建房间\n"
      "3.加入房间\n"
      "4.开始战斗\n"
      "5.退出游戏")
players = {}
rooms = {}
while 1:
    number = input("请输入所需的数字:")
    if number == "1":
        name= input("请输入角色的姓名：")
        sex = input("请输入角色的性别：")
        players[name] = Player(name,sex)
        print(players)
        print(f"创建了姓名为{name}的{sex}角色")
    elif number == "2":
        rname = input("请输入房间名：")
        rooms[rname] = Room(rname)
        print(f"创建了{rname}房间")
    elif number == '3':
        print(f"已创建的角色{list(players.keys())},已创建的房间{list(rooms.keys())}")
        players_name = input("选择要加入的角色:")
        rooms_name = input("选择要加入的房间名:")
        rooms[rooms_name].addplr(players[players_name])
    elif number == '4':
        p_name = input("请输入要PK的角色:")
        count = 1
        while 1:
            print(f"第{count}回合".center(30,'='))
            players[name].PK(players[p_name])
            players[p_name].PK(players[name])
            count +=1
    elif number == '5':
        print("游戏退出")
        exit()














